<template>
	<view class="body">
		<view class="step-body"><uni-steps :options="[{ title: '基本信息' }, { title: '上传证照' }, { title: '完成备案' }]" :active="active"></uni-steps></view>
		<form class="uni-form" @submit="formSubmit">
			<view id="base" v-if="active == 0">
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						姓名
					</label>
					<input class="uni-input" type="text" disabled v-model="userInfo.AAC003" placeholder-class="placeholder" />
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						身份证号
					</label>
					<input class="uni-input" type="idcard" disabled v-model="userInfo.AAC002" placeholder-class="placeholder" />
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">社保卡号</label>
					<input class="uni-input" type="idcard" disabled v-model="userInfo.AAZ500" placeholder-class="placeholder" />
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						联系电话
					</label>
					<input class="uni-input" type="number" maxlength="11" @confirm="regPhone" @blur="regPhone" v-model="userInfo.AAE005" placeholder-class="placeholder" />
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">联系人</label>
					<input class="uni-input" type="text" v-model="userInfo.AAE004" placeholder-class="placeholder" />
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						就医地
					</label>
					<view class="uni-input my-picker" @tap="openPopup('province')">{{ userInfo.AKC801_NAME }}</view>
				</view>
				<view class="uni-form-item uni-column" v-if="formType == 3 || userInfo.AKA085==4">
					<label class="title">转出医疗机构</label>
					<view class="uni-input my-picker" @tap="selectHos('out')">{{ userInfo.ZCJGMC }}</view>
				</view>
				<view class="uni-form-item uni-column" v-if="formType == 3 || userInfo.AKA085==4">
					<label class="title">转往医疗机构</label>
					<view class="uni-input my-picker" @tap="selectHos('in')">{{ userInfo.ZWJGMC }}</view>
				</view>
				<view class="uni-form-item uni-column" @click="onShowDatePicker('AAE127')">
					<label class="title">
						<text style="color:red;">⁎</text>
						申报日期
					</label>
					<view class="uni-input" :value="userInfo.AAE127">{{ userInfo.AAE127 }}</view>
				</view>
				<view class="uni-form-item uni-column" @click="onShowDatePicker('AAE030')">
					<label class="title">
						<text style="color:red;" v-if="isMust">⁎</text>
						待遇开始日期
					</label>
					<view class="uni-input" :value="userInfo.AAE030">{{ userInfo.AAE030 }}</view>
				</view>
				<view class="uni-form-item uni-column" @click="onShowDatePicker('AAE031')">
					<label class="title">
						<text style="color:red;" v-if="isMust">⁎</text>
						待遇终止日期
					</label>
					<view class="uni-input" :value="userInfo.AAE031">{{ userInfo.AAE031 }}</view>
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						备案类别
					</label>
					<picker class="my-picker" disabled="true" v-model="userInfo.AKAIndex085" :range="renyuanArr" range-key="AAA103" mode="selector" @change="changeRenyuan">
						<view class="uni-input">{{ userInfo.AKA085_NAME }}</view>
					</picker>
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">
						<text style="color:red;">⁎</text>
						险种类型
					</label>
					<view class="uni-input">{{ userInfo.AAE140_NAME }}</view>
				</view>
				<view class="uni-form-item uni-column">
					<label class="title">备注</label>
					<textarea v-model="userInfo.BZ" />
				</view>
				<mx-date-picker :show="showPicker" type="date" format="yyyy-mm-dd" @confirm="onSelected" @cancel="onCancel" />
			</view>
			<view id="base" v-if="active == 1">
				<view class="uni-form-item  uni-column">
					<!-- 
			
				<view class="add-icon">
					<image @tap="chooseImg" class="add-Img" src="../../static/image/addImg.png" mode="aspectFit"></image>
				</view>
				<view class="image-wrap" >
					<view class="image-item" :class="{'hover-image':currentIndex==imgIndex}"  v-for="(image,imgIndex) in imageArr" :key="imgIndex">
						<view class="close" @tap="deleteImg(imgIndex)">
							<image style="width:50upx;" src="../../static/image/error.png" mode="widthFix"></image>
						</view>
						<image style="width: 100%;height: 100%;" :data-index="imgIndex"  @tap="showCloseBtn($event)"  :src="image" mode="scaleToFill"></image>
					</view>
				</view> -->
					<view class="food-list">
						<text class="conPic-tip">上传证照</text>

						<view class="food-area">
							<view class="food-item" :class="{ 'hover-image': currentIndex == 'SFZ_Z' }" @tap="chooseImg('SFZ_Z')">
								<image class="img-avatar" :src="userInfo.SFZ_Z" data-index="SFZ_Z" mode="scaleToFill" @longtap="deleteImg('SFZ_Z')"></image>
								<!-- <image :src="userInfo.SFZ_Z" :data-index="imgIndex" @tap="showCloseBtn($event)"/> -->
								<text class="food-name">身份证正面</text>
							</view>

							<view class="food-item" :class="{ 'hover-image': currentIndex == 'SFZ_F' }" @tap="chooseImg('SFZ_F')">
								<image class="img-avatar" :src="userInfo.SFZ_F" data-index="SFZ_F" mode="scaleToFill" @longtap="deleteImg('SFZ_F')"></image>
								<!-- <image :src="userInfo.SFZ_F" :data-index="imgIndex" @tap="showCloseBtn($event)"/> -->
								<text class="food-name">身份证反面</text>
							</view>
							<view class="food-item" :class="{ 'hover-image': currentIndex == 'SBK_Z' }" @tap="chooseImg('SBK_Z')">
								<image class="img-avatar" :src="userInfo.SBK_Z" data-index="SBK_Z" mode="scaleToFill" @longtap="deleteImg('SBK_Z')" />
								<!-- <image :src="userInfo.SBK_Z" :data-index="imgIndex" @tap="showCloseBtn($event)"/> -->
								<text class="food-name">社保卡正面</text>
							</view>
							<view class="food-item" key="SBK_F" :class="{ 'hover-image': currentIndex == 'SBK_F' }" @tap="chooseImg('SBK_F')">
								<image class="img-avatar" :src="userInfo.SBK_F" data-index="SBK_F" mode="scaleToFill" @longtap="deleteImg('SBK_F')" />
								<!-- <image :src="userInfo.SBK_F" :data-index="imgIndex" @tap="showCloseBtn($event)"/> -->
								<text class="food-name">社保卡反面</text>
							</view>
						</view>

						<view class="uni-form-item uni-column">
							<label class="title">
								<text style="color:red;">⁎</text>
								请选择证明
							</label>
							<picker class="my-picker" :range="imageType" range-key="name" @change="changeImageType">
								<view class="uni-input">{{ chooseImageText }}</view>
							</picker>
						</view>

						<view class="food-area">
							<view class="food-item" :class="{ 'hover-image': currentIndex == 'OTHER_IMG' }" @tap="chooseImg('OTHER_IMG')">
								<image class="img-avatar" :src="userInfo.OTHER_IMG" data-index="OTHER_IMG" mode="scaleToFill" @longtap="deleteImg('OTHER_IMG')" />
								<text class="food-name">{{ chooseImageText }}</text>
							</view>
							<view class="food-item-last">
								<view class="addPic-box"><image class="addPic-box-img" src="/static/image/addImg.png" @tap="chooseImg('')"></image></view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="box-body" v-if="active == 2">
				<view class="body-img"><image class="success-img" src="/static/image/success.png" mode=""></image></view>
				<view class="body-text">
					<text>备案上报成功</text>
					</p></br><button type="primary" @tap="toindex" style="display:inline-block;width: 50%;">返回首页</button>
				</view>
			</view>
			<button v-if="active == 0" type="primary" :disabled="!isLogin" @click="step(1)" style="margin-top: 30upx;width: 50%;">下一步</button>

			<div class="box" style="width:100%; text-align:center;">
				<button v-if="active == 1" type="primary" :disabled="!isLogin" @click="step(0)" style="display:inline-block;margin-top: 30upx;width: 40%;">上一步</button>
				<button v-if="active == 1" type="primary" :disabled="!isLogin" form-type="submit" style="display:inline-block;margin-top: 30upx;margin-left: 20upx;; width: 40%;">
					下一步
				</button>
			</div>
		</form>

		<!-- 机构 -->
		<areaSelect ref="linkAddress" :initProvince="initProvince" :height="height" @confirmCallback="confirmCallback"></areaSelect>
	</view>
</template>

<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
import { pathToBase64, base64ToPath } from '@/config/images-tools.js';
import uniSteps from '@/components/uni-steps/uni-steps.vue';
import areaSelect from '@/components/area-select/linkAddress.vue';
import MxDatePicker from '@/components/mx-datepicker/mx-datepicker.vue';

export default {
	components: { uniPopup, uniSteps, areaSelect, MxDatePicker },
	data() {
		return {
			showPicker: false,
			inputName: 'AAE030',
			formType: 1,
			active: 0,
			currentIndex: null,
			height: '500px',
			userInfo: {
				AAC002: '', //身份证号码
				AAC003: '', //姓名
				AAZ500: '', //社保卡号
				AAE005: '', //电话
				AAE004: '', //联系人
				ZYLX: '', //转院类型
				ZWYY: '', //转外原因
				AAZ267: '', //备案编号
				ZCJGMC: '', //转出医疗机构名称
				ZCJGDM: '', //转出医疗机构代码
				ZWJGMC: '', //转往医疗机构名称
				ZWJGDM: '', //转往医疗机构代码
				AAE030: '', //待遇开始日期
				AAE031: '', //待遇终止日期
				AAE127: this.$common.getDate(new Date()), //申报日期

				AKC803: '', //参保地行政区域代码

				AKC801: '', //就医地行政区划代码
				AKC801_NAME: '', //就医地行政区划名称

				AAE006: '', //异地居住地址
				AKA085: '2', //人员类别
				AKA085_NAME: '', //人员名称
				AKAIndex085: null,

				AAE140: '', //险种类型
				AAE140_NAME: '', //险种类型名称
				AAEIndex140: null,

				BG_FLAG: '1', //	变更标志
				BZ: '', //备注
				SFZ_Z: '', //身份证正面上传
				SFZ_F: '', //身份证反面上传
				SBK_Z: '', //社保卡正面上传
				SBK_F: '', //社保卡反面上传
				OTHER_IMG: '', //其他资料图片上传
				BACL: '' //其他资料类型代码
			},

			Loginer: {},
			isLogin: true,
			current: '',
			imageArr: [],
			imageNameArr: [],
			pageFlag: false,
			pageIndex: 1,
			totalPage: 1,
			renyuanArr: [],
			xianzhongArr: [],
			status: 'more',
			imageLoad: false,
			SNW_FLAG: 0,
			isMust: false,
			initProvince: [],
			contentText: {
				contentdown: '查看更多',
				contentrefresh: '加载中',
				contentnomore: '没有更多'
			},
			chooseImageText: '请选择相关证明',
			imageType1: [
				{ key: '', name: '请选择相关证明' },
				{ key: '101', name: '常驻人口登记卡' },
				{ key: '102', name: '异地身份证' }
			],
			imageType2: [
				{ key: '', name: '请选择相关证明' },
				{ key: '201', name: '居住证' },
				{ key: '202', name: '暂住证' },
				{ key: '203', name: '社区证明' },
				{ key: '204', name: '房产证正文页' },
				{ key: '205', name: '长期租房合同' }
				],
			imageType3: [
				{ key: '', name: '请选择相关证明' }, 
				{ key: '301', name: '单位派出文件' }, 
				{ key: '302', name: '单位证明' },
				],
			imageType4: [
				{ key: '', name: '请选择相关证明' },
				{ key: '401', name: '转诊证明' }, 
				{ key: '402', name: '转诊单(或手续)' }
			],
			imageType5: [
				 { key: '', name: '请选择相关证明' },
				 { key: '601', name: '录取通知书' }, 
				 { key: '602', name: '学生证' }, 
				{ key: '603', name: '学校开学证明' },
			],
			imageType6: [
				 { key: '', name: '请选择相关证明' },
				 { key: '501', name: '工资表' }, 
				 { key: '502', name: '证明材料' }, 
				{ key: '503', name: '营业执照' },
			],

			
		};
	},
	computed: {
		allArr: function() {
			return [this.provinceArr, this.cityArr, this.areaArr, this.hosArr];
		},
		imageType() {
			var Loginer = uni.getStorageSync('userInfo');
			if (this.formType == 1 && this.SNW_FLAG == 1  && Loginer.AAE140=='31') {
				return this.imageType1;
			} else if (this.formType == 1 && this.SNW_FLAG == 1  && Loginer.AAE140=='390') {
				return this.imageType2;
			}else if (this.formType == 2 && this.SNW_FLAG == 1 && Loginer.AAE140=='31') {
				return this.imageType2;
			} else if (this.formType == 2 && this.SNW_FLAG == 1 && Loginer.AAE140=='390') {
				return this.imageType6;
			}else if (this.formType == 3 && this.SNW_FLAG == 1 && Loginer.AAE140=='31') {
				return this.imageType3;
			}else if (this.formType == 3 && this.SNW_FLAG == 1 && Loginer.AAE140=='390') {
				return this.imageType4;
			}  else if (this.formType == 4 && this.SNW_FLAG == 1 && Loginer.AAE140=='390') {
				return this.imageType5;
			} else if (this.formType == 4 && this.SNW_FLAG == 1 && Loginer.AAE140=='31') {
				return this.imageType4;
			} else if (this.formType == 1 && this.SNW_FLAG == 2 && Loginer.AAE140=='31') {
				return this.imageType1;
			} else if (this.formType == 1 && this.SNW_FLAG == 2 && Loginer.AAE140=='390') {
				return this.imageType2;
			}  else if (this.formType == 2 && this.SNW_FLAG == 2 && Loginer.AAE140=='31') {
				return this.imageType2;
			} else if (this.formType == 2 && this.SNW_FLAG == 2  && Loginer.AAE140=='390') {
				return this.imageType6;
			}  else if (this.formType == 3 && this.SNW_FLAG == 2 && Loginer.AAE140=='31') {
				return this.imageType3;
			} else if (this.formType == 3 && this.SNW_FLAG == 2 && Loginer.AAE140=='390') {
				return this.imageType4;
			}  else if (this.formType == 4 && this.SNW_FLAG == 2  && Loginer.AAE140=='31') {
				return this.imageType4;
			}  else if (this.formType == 4 && this.SNW_FLAG == 2  && Loginer.AAE140=='390') {
				return this.imageType5;
			} 
		}
	},
	filters: {
		formatNull(val) {
			return val ? val : '';
		}
	},
	methods: {
		// 验证手机号
		regPhone() {
			var reg = this.$common.isPhoneNumber(this.userInfo.AAE005);
			var msg = this.userInfo.AAE005 ? '请填写正确的手机号' : '请填写手机号';
			console.log(reg);
			if (!reg) {
				this.$common.errorToShow(msg);
				return false;
			} else {
				return true;
			}
		},
		//医院加载更多
		loadMore() {
			console.log(this.targetIndex);
			if (this.targetIndex == 3) {
				if (this.pageIndex < this.totalPage) {
					this.pageIndex++;
					if (this.pageIndex > this.totalPage) {
						this.pageIndex = this.totalPage;
					}
					this.getHospital(this.current);
				} else {
					uni.showToast({
						title: '没有更多',
						image: '../../static/image/info.png'
					});
				}
			}
		},
		// 拍照
		takePhoto(imgKey) {
			var self = this;
			if (self.imageArr.length >= 3) {
				self.$common.errorToShow('只能选择三张图片');
				return;
			}
			uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['camera'],
				success(res) {
					//#ifdef MP-WEIXIN
					//图片压缩并转base64
					self.$common.weixin_img(0, res);
					self.setImage(res.tempFiles[0].Base64_Path, imgKey);
					//#endif
					//#ifdef APP-PLUS
					//图片压缩
					self.$common.app_img(res, function(Base64) {
						self.setImage(Base64, imgKey);
					});
					//#endif
					//#ifdef H5
					self.$common.h5_img(
						res,
						{
							quality: 0.5
						},
						function(base64Codes) {
							self.setImage(base64Codes, imgKey);
						}
					);
					//#endif
				}
			});
		},
		// 相册
		album(imgKey) {
			var self = this;
			if (self.imageArr.length >= 3) {
				self.$common.errorToShow('只能选择三张图片');
				return;
			}
			uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album'],
				success(res) {
					// 并行
					// Promise.all(res.tempFilePaths.map(path => pathToBase64(path)))
					//   .then(res2 => {
					// 	self.setImage(res2[0]);
					//   })
					//   .catch(error => {
					//     console.error(error)
					//   })
					//#ifdef MP-WEIXIN
					//图片压缩并转base64
					self.$common.weixin_img(0, res);
					self.setImage(res.tempFiles[0].Base64_Path, imgKey);
					//#endif
					//#ifdef APP-PLUS
					//图片压缩
					self.$common.app_img(res, function(Base64) {
						self.setImage(Base64, imgKey);
					});
					//#endif
					//#ifdef H5
					self.$common.h5_img(
						res,
						{
							quality: 0.2
						},
						function(base64Codes) {
							self.setImage(base64Codes, imgKey);
						}
					);
					//#endif
				}
			});
		},
		chooseImg(imgKey) {
			if (imgKey == '' && this.userInfo.SFZ_Z != '' && this.userInfo.SFZ_F != '' && this.userInfo.SBK_Z != '' && this.userInfo.SBK_F != '' && this.userInfo.BACL == '') {
				this.$common.errorToShow('请选择证明类型');
				return;
			}
			var self = this;
			uni.showActionSheet({
				itemList: ['拍照', '相册'],
				success: function(res) {
					if (res.tapIndex == '0') {
						self.takePhoto(imgKey);
					} else if (res.tapIndex == '1') {
						self.album(imgKey);
					}
				},
				fail: function(res) {}
			});
		},
		setImage(res, imgKey) {
			if (imgKey != '') {
				this.userInfo[imgKey] = res;
				return;
			}
			if (this.userInfo.SFZ_Z == '') {
				this.userInfo.SFZ_Z = res;
			} else if (this.userInfo.SFZ_F == '') {
				this.userInfo.SFZ_F = res;
			} else if (this.userInfo.SBK_Z == '') {
				this.userInfo.SBK_Z = res;
			} else if (this.userInfo.SBK_F == '') {
				this.userInfo.SBK_F = res;
			} else if (this.userInfo.OTHER_IMG == '') {
				this.userInfo.OTHER_IMG = res;
			}
		},
		clearImage(imgKey) {
			if (imgKey == 'SFZ_Z') {
				this.userInfo.SFZ_Z = '';
			} else if (imgKey == 'SFZ_F') {
				this.userInfo.SFZ_F = '';
			} else if (imgKey == 'SBK_Z') {
				this.userInfo.SBK_Z = '';
			} else if (imgKey == 'SBK_F') {
				this.userInfo.SBK_F = '';
			} else if (imgKey == 'OTHER_IMG') {
				this.userInfo.OTHER_IMG = '';
			}
		},
		loadImages(AAZ267, AAC002) {
			const self = this;
			if (self.imageLoad) {
				return;
			}
			self.$request(
				'S1018',
				{
					AAZ267: AAZ267,
					AAC002: AAC002
				},
				'POST',
				function(res) {
					if (res.data.CODE == '0') {
						for (var i = 0; i < res.data.DATA.length; i++) {
							var info = res.data.DATA[i];
							var imageData = info.FJINFO;
							var imgKey = info.FJ_NAME;
							var BACL = info.BACL;
							var BACL_NAME = info.BACL_NAME;
							if (imgKey == 'SFZ_Z') {
								self.userInfo.SFZ_Z = imageData;
							} else if (imgKey == 'SFZ_F') {
								self.userInfo.SFZ_F = imageData;
							} else if (imgKey == 'SBK_Z') {
								self.userInfo.SBK_Z = imageData;
							} else if (imgKey == 'SBK_F') {
								self.userInfo.SBK_F = imageData;
							} else if (imgKey == 'OTHER_IMG') {
								self.userInfo.OTHER_IMG = imageData;
								self.userInfo.BACL = BACL;
								self.chooseImageText = BACL_NAME;
							}
						}
					}
				}
			);
		},
		deleteImages(imgKey) {
			const self = this;
			self.$request(
				'S1017',
				{
					AAZ267: self.Loginer.AAZ267,
					AAC002: self.Loginer.AAC002,
					FJ_NAME: imgKey
				},
				'POST',
				function(res) {
					if (res.data.CODE == '0') {
						self.clearImage(imgKey);
					} else {
						self.$common.errorToShow('删除失败请重试');
					}
				}
			);
		},
		verifyForm() {
			var arr = {
				AAC003: '姓名', //
				AAC002: '身份证号',
				AAE005: '联系电话',
				AKC801: '就医地',
				AAE127: '申报日期'
			};

			for (var key in arr) {
				if (key != 'AAE005' && this.userInfo[key] == '') {
					this.$common.errorToShow('请完善' + arr[key] + '信息');
					return false;
				} else if (key == 'AAE005') {
					var result = this.regPhone();
					if (!result) {
						return false;
					}
				}
			}
			return true;
		},
		step(index) {
			var self = this;

			if (index == 1) {
				if (!this.verifyForm()) {
					return false;
				}
				if (!this.isMust) {
					if (this.userInfo.AAE030 == null || this.userInfo.AAE030 == '') {
					    this.userInfo.AAE030 = this.$common.getDate(new Date());
					}
				} else {
					if (this.userInfo.AAE030 == null || this.userInfo.AAE030 == '') {
						this.$common.errorToShow('请完善待遇开始日期信息');
						return false;
					}
					if (this.userInfo.AAE031 == null || this.userInfo.AAE031 == '') {
						this.$common.errorToShow('请完善待遇终止日期信息');
						return false;
					}
				}
			}
			self.active = index;
		},
		formSubmit() {
			var self = this;
			if (!this.verifyForm()) {
				return false;
			}
			if (this.SNW_FLAG == 1 && this.formType == 1) {
				//this.userInfo.AAE030 = this.$common.getDate(new Date());
			} else {
				if (this.userInfo.AAE030 == '') {
					this.$common.errorToShow('请完善待遇开始日期信息');
					return false;
				}
				if (this.userInfo.AAE031 == '') {
					this.$common.errorToShow('请完善待遇终止日期信息');
					return false;
				}
			}
			if (this.userInfo.SFZ_Z == '') {
				this.$common.errorToShow('请完善身份证正面图片');
				return false;
			} else if (this.userInfo.SFZ_F == '') {
				this.$common.errorToShow('请完善身份证反面图片');
				return false;
			} else if (this.userInfo.SBK_Z == '') {
				this.$common.errorToShow('请完善社保卡正面图片');
				return false;
			} else if (this.userInfo.SBK_F == '') {
				this.$common.errorToShow('请完善社保卡反面图片');
				return false;
			} else if (this.userInfo.OTHER_IMG == '') {
				this.$common.errorToShow('请完善证明图片');
				return false;
			}

			if (this.userInfo.OTHER_IMG != '' && this.userInfo.BACL == '') {
				this.$common.errorToShow('请完善证明类别信息');
				return false;
			}
			if (this.userInfo.AAE030 == null || this.userInfo.AAE030 == '') {
				this.userInfo.AAE030 = this.userInfo.AAE127;
			}

			this.userInfo.AAE030 = this.userInfo.AAE030.replace(/-/g, '');
			this.userInfo.AAE031 = this.userInfo.AAE031 ? this.userInfo.AAE031.replace(/-/g, '') : '';
			this.userInfo.AAE127 = this.userInfo.AAE127.replace(/-/g, '');
             console.info(this.userInfo.AAE030)
			this.$request('S1003', this.userInfo, 'POST', function(res) {
				console.log(res);
				if (res.data.CODE == '0') {
					self.active = 2;
				} else {
					self.$common.errorToShow(res.data.MSG);
				}
			});
		},
		onShowDatePicker(type) {
			this.showPicker = true;
			this.inputName = type;
		},
		onSelected(e) {
			//选择
			this.showPicker = false;
			if (e) {
				this.userInfo[this.inputName] = e.value;
			}
		},
		onCancel(e) {
			this.showPicker = false;
		},
		changeShow(name) {
			this.$refs[name].show();
		},
		confirm(res) {
			this.userInfo.target = res.data.label;
		},
		selectHos(type) {
			uni.navigateTo({
				url: '../hospital-select/hos-list?type=' + type + '&SNW_FLAG=' + this.SNW_FLAG
			});
		},

		toindex() {
			uni.switchTab({
				url: '../index/index'
			});
		},

		//点击弹出弹窗
		openPopup: function() {
			this.height = '550rpx';
			//显示
			this.show_popup();
		},
		//显示弹窗
		show_popup: function() {
			this.$refs.linkAddress.show();
		},
		//回掉
		confirmCallback: function(select) {
			if (select) {
				var index = select.length;
				this.userInfo.AKC801_NAME = select[index - 1].AREA_NAME;
				this.userInfo.AKC801 = select[index - 1].AREA_CODE;
			}
		},

		changeImageType(e) {
			this.chooseImageText = this.imageType[e.detail.value].name;
			this.userInfo.BACL = this.imageType[e.detail.value].key;
		},

		deleteImg(imgKey) {
			const self = this;
			if (this.userInfo[imgKey] == '') {
				return;
			}
			clearInterval(this.Loop); //再次清空定时器，防止重复注册定时器
			this.Loop = setTimeout(
				function() {
					uni.showModal({
						title: '删除',
						content: '请问要删除本条吗？',
						success: function(res) {
							if (res.confirm) {
								if (self.userInfo.BG_FLAG == 2) {
									self.deleteImages(imgKey);
								} else {
									uni.showLoading({ title: '正在删除中...' });
									self.clearImage(imgKey);
									setTimeout(function() {
										uni.hideLoading();
									}, 300);
								}
							}
						}
					});
				}.bind(this),
				1000
			);
		},
		deleteEnd() {
			clearInterval(this.Loop);
		},
		showCloseBtn(e) {
			var self = this;
			//
			this.currentIndex = e.currentTarget.dataset.index;
			setTimeout(function() {
				self.currentIndex = null;
			}, 5000);
		},
		changeRenyuan(e) {
			this.userInfo.AKAIndex085 = e.target.value;
			this.userInfo.AKA085 = this.renyuanArr[e.target.value].AAA102;
			this.userInfo.AKA085_NAME = this.renyuanArr[e.target.value].AAA103;
		},
		changeXianzhong(e) {
			this.userInfo.AKAIndex085 = e.target.value;
			this.userInfo.AAE140 = this.xianzhongArr[e.target.value].AAA102;
			this.userInfo.AAE140_NAME = this.xianzhongArr[e.target.value].AAA103;
		},
		formateDate(val) {
			var year = val.substring(0, 4);
			var month = val.substring(4, 6);
			var day = val.substring(6, 8);
			return year + '-' + month + '-' + day;
		}
	},
	onShow() {
		var isLogin = uni.getStorageSync('isLogin'),
			self = this;
		this.isLogin = isLogin;
		if (isLogin) {
			if (this.userInfo.BG_FLAG == 2) {
				this.Loginer = uni.getStorageSync('ItemInfo');
				if (this.Loginer.IS_FJ == 1) {
					self.loadImages(this.Loginer.AAZ267, this.Loginer.AAC002);
					self.imageLoad = true;
				}
				this.userInfo.AAZ267 = this.Loginer.AAZ267;
				this.userInfo.AAC003 = this.Loginer.AAC003; //姓名
				this.userInfo.AAC002 = this.Loginer.AAC002; //身份证号码
				this.userInfo.AAZ500 = this.Loginer.AAZ500; //社保卡号
				this.userInfo.AAE005 = this.Loginer.AAE005; //电话
				this.userInfo.AAE004 = this.Loginer.AAE004; //联系人
				this.userInfo.ZYLX = this.Loginer.ZYLX ? this.Loginer.ZYLX : ''; //转院类型
				this.userInfo.ZWYY = this.Loginer.ZWYY ? this.Loginer.ZWYY : ''; //转外原因
				if(this.userInfo.ZCJGDM == ''){
					this.userInfo.ZCJGMC = this.Loginer.ZCJGMC ? this.Loginer.ZCJGMC : ''; //转出医疗机构名称
					this.userInfo.ZCJGDM = this.Loginer.ZCJGDM ? this.Loginer.ZCJGDM : ''; //转出医疗机构代码
				}　　　
				if(this.userInfo.ZWJGDM == ''){
					this.userInfo.ZWJGMC = this.Loginer.ZWJGMC ? this.Loginer.ZWJGMC : ''; //转往医疗机构名称
					this.userInfo.ZWJGDM = this.Loginer.ZWJGDM ? this.Loginer.ZWJGDM : ''; //转往医疗机构代码
				}
				this.userInfo.AAE030 = this.formateDate(this.Loginer.AAE030 + ''); //待遇开始日期
				this.userInfo.AAE031 = this.formateDate(this.Loginer.AAE031 + ''); //待遇终止日期
				this.userInfo.AAE127 = this.formateDate(this.Loginer.AAE127 + ''); //申报日期
				this.userInfo.AKC803 = this.Loginer.AKC803; //参保地行政区域代码
				this.userInfo.AKC803_NAME = this.Loginer.AKC803_NAME;
				this.userInfo.AKC801 = this.Loginer.AKC801; //就医地行政区划代码
				this.userInfo.AKC801_NAME = this.Loginer.AKC801_NAME; //就医地行政区划名称
				this.userInfo.AAE006 = this.Loginer.AAE006; //异地居住地址
				this.userInfo.AKA085 = this.Loginer.AKA085; //人员类别
				this.userInfo.AKA085_NAME = this.Loginer.AKA085_NAME; //人员名称
				this.userInfo.AAE140 = this.Loginer.AAE140; //险种类型
				this.userInfo.AAE140_NAME = this.Loginer.AAE140_NAME; //险种类型名称
				this.userInfo.BZ = this.Loginer.BZ;
			} else {
				this.Loginer = uni.getStorageSync('userInfo');
				console.log('用户信息', this.Loginer);
				this.userInfo.AAC003 = this.Loginer.AAC003; //姓名
				this.userInfo.AAC002 = this.Loginer.AAC002; //身份证号码
				this.userInfo.AAZ500 = this.Loginer.AAZ500;
				this.userInfo.AAE140 = this.Loginer.AAE140; //险种类型
				this.userInfo.AKC803 = this.Loginer.AKC803; //参保地行政区域代码
				this.userInfo.AAE005 = this.Loginer.username;
			}
			var queryValue = this.Loginer.AAE140 == '31' ? 'AKA085' : 'AKA085_CXJM';
			//人员类别
			this.$request('S8888', { AAA100: queryValue }, 'POST', function(res) {
				if (res.data.CODE == '0') {
					self.renyuanArr = res.data.DATA;
					self.userInfo.AKAIndex085 = _.findIndex(res.data.DATA, { AAA102: self.userInfo.AKA085 }); //人员类别序号
					self.userInfo.AKA085_NAME = _.filter(res.data.DATA, { AAA102: self.userInfo.AKA085 })[0].AAA103;
				}
			});

			//   险种类型
			this.$request('S8888', { AAA100: 'AAE140' }, 'POST', function(res) {
				if (res.data.CODE == '0') {
					self.xianzhongArr = res.data.DATA;
					self.userInfo.AAEIndex140 = _.findIndex(res.data.DATA, { AAA102: self.Loginer.AAE140 });
					if (self.userInfo.BG_FLAG != '2') {
						self.userInfo.AAE140_NAME = _.filter(self.xianzhongArr, { AAA102: self.Loginer.AAE140 })[0].AAA103;
					}
				}
			});
		}
	},
	onLoad(param) {
		var user = uni.getStorageSync('userInfo'),self = this;;
		if (param.BG_FLAG == 2) {
			self.userInfo.BG_FLAG = param.BG_FLAG;
		}
		if (param.formType) {
			self.formType = param.formType;
			self.userInfo.AKA085 = param.formType;
		}
		if (param.SNW_FLAG) {
			self.SNW_FLAG = param.SNW_FLAG;
			if (self.SNW_FLAG == 1) {
				self.initProvince[0] = { AREA_CODE: '620000', AREA_NAME: '甘肃省' };
			} else {
				self.initProvince = [];
			}
		}
		if (user.AAE140 == 31) {
			if (self.formType == 1 || self.formType == 2) {
				self.isMust = false;
			} else {
				self.isMust = true;
			}
		} else {
			if (self.formType == 1) {
				self.isMust = false;
			} else {
				this.isMust = true;
			}
		}

		uni.$on('hosClick', item => {
			if (item.type == 'out') {
				self.userInfo.ZCJGDM = item.AKB020;
				self.userInfo.ZCJGMC = item.AKB021;
			} else {
				self.userInfo.ZWJGDM = item.AKB020;
				self.userInfo.ZWJGMC = item.AKB021;
			}
		});
	}
};
</script>

<style>
.step-body {
	/* #ifndef APP-NVUE */
	display: block;
	/* #endif */
	padding: 25px;
	flex-direction: row;
}
.body {
	padding: 0 10upx;
}
.placeholder {
	font-size: 16px;
}
.add-icon {
	padding: 30upx 10upx;
}
.add-Img {
	width: 150upx;
	height: 150upx;
}
.image-wrap {
	padding: 10upx 20upx 30upx;
	display: flex;
	justify-content: flex-start;
	flex-direction: row;
	flex-wrap: wrap;
}
.image-item {
	position: relative;
	width: 180upx;
	height: 240upx;
	margin-top: 30upx;
	margin-left: 30upx;
	margin-right: 30upx;
}
.image-item .close {
	box-sizing: border-box;
	position: absolute;
	top: -10upx;
	left: 0;
	z-index: 99;
	width: 100%;
	height: 0upx;
	background: rgba(0, 0, 0, 0.3);
	display: flex;
	justify-content: flex-end;
	padding-right: 2upx;
	overflow: hidden;
	transition: height 0.5s ease;
}
.hover-image.image-item .close {
	height: 50upx;
}

.conText {
	width: 100%;
	height: 244upx;
	border-bottom: 1px solid #eceaea;
	padding: 38upx 0;
	box-sizing: border-box;
	overflow: hidden;
}

.food-list {
	width: 100%;
	height: auto;
	display: table;
	margin-top: 30upx;
	background: #f6f6f6;
}

.food-area {
	/* 		width: 93.4%;
		margin-left: auto;
		margin-right: auto;
		display: table;
		padding-bottom: 10upx; */
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: space-around;
}
/* 	.food-item:nth-child(odd){
		margin-top: 20upx;
		width: 310upx;
		float: left;
	} */
/* 	.food-item:nth-child(even){
		margin-top: 20upx;
		width: 310upx;
		float: right;
	} */

.food-item {
	position: relative;
	width: 310upx;
	/* height: 230upx; */
	margin-top: 20upx;
	border-radius: 20upx;
	margin-bottom: 50upx;
	font-size: 0;
}
.food-item .close {
	box-sizing: border-box;
	position: absolute;
	top: 1upx;
	left: 0;
	z-index: 99;
	width: calc(100% + 1px);
	height: 0upx;
	background: rgba(0, 0, 0, 0.3);
	display: flex;
	justify-content: flex-end;
	padding-right: 2upx;
	overflow: hidden;
	transition: height 0.5s ease;
	border-radius: 20upx 20upx 0 0;
}

.hover-image.food-item .close {
	height: 50upx;
}

.food-item .img-avatar {
	width: 310upx;
	height: 235upx;
	border: 1px solid #303133;
	border-radius: 10px;
	background: #fff;
}
.food-name {
	/* 	width: 293upx;
		margin-left: auto;
		margin-right: auto; */
	display: block;
	font-size: 27upx;
	font-weight: bold;
	line-height: 0;
}
.addPic-box {
	margin-top: 20upx;
	width: 310upx;
	height: 230upx;
	float: right;
	line-height: 230upx;
	text-align: center;
}
.addPic-box .addPic-box-img {
	width: 136upx;
	height: 136upx;
	vertical-align: middle;
}

.box-body {
	width: 100%;
	height: auto;
	margin-top: 30upx;
}
.body-img {
	width: 100%;
	height: auto;
	text-align: center;
}
.body-img .success-img {
	width: 120upx;
	height: 120upx;
}
.body-text {
	width: 410upx;
	margin-left: auto;
	margin-right: auto;
	margin-top: 60upx;
	text-align: center;
}
</style>
